﻿/* ==============================================================================
 * 功能描述：BattlePanelSkillItem  
 * 
 * 创 建 者：郑镇泉
 * 
 * 创建日期：2016/5/8 15:56:53
 * ==============================================================================*/
using UnityEngine;
using System.Collections;
using DG.Tweening;
using UnityEngine.UI;
using ZZQFrameWork;

public class BattlePanelSkillItem : MonoBehaviour,IPool
{
    private SkillVO data;

    public SkillVO Data
    {
        get { return data; }
        set
        {
            data = value;
            UpdateShow();
        }
    }

    private Image iconImage;
    private Image coldImage;

    void Awake()
    {
        iconImage = transform.GetComponentByPath<Image>("Icon");
        coldImage = transform.GetComponentByPath<Image>("Cold");
    }

    private void UpdateShow()
    {
        iconImage.sprite = UIAtlasManager.Instance.GetUIAtlasByName("Skill_Atlas").GetSprite(Data.icon);
        if(Data.IsCold)coldImage.gameObject.SetActive(true);
        else
        {
            coldImage.gameObject.SetActive(false);
        }
    }

    public bool OnUseSkill()
    {
        Debug.Log("当前技能冷却时间："+Data.coldTime+"，现在是否有冷却中："+Data.IsCold);
        if (Data.IsCold) return false;
        //释放技能
        Debug.Log("开始释放技能");
        Data.IsCold = true;
        coldImage.gameObject.SetActive(true);
        Tweener tweener=coldImage.DOFillAmount(0, Data.coldTime);
        tweener.OnComplete(() =>
        {
            coldImage.fillAmount = 1;
            coldImage.gameObject.SetActive(false);
            tweener.Kill();
        });
        return true;
    }

    private void OnCastSkill()
    {
        
    }

    public void Spawn()
    {
    }

    public void UnSpawn()
    {
    }
}